home *** CD-ROM | disk | FTP | other *** search
- UNIT ztfdd;
-
- { A Text File Device Driver whose formatted output is a PChar
-
- Usage:
- Include the ZTFDD unit in your program's "Uses" clause.
- Write(Zout, ..Anything that can be used with Write()..);
- The resulting PChar output can be retreived with function GetZ.
- See ZFDDTEST.PAS for a usage example.
-
- Notes:
- There is no need to Assign, Rewrite, or Close "Zout".
-
- Don't use WriteLn(Zout,..) unless you want the PChar to end with ^M^J
-
- The maximum length of the resulting PChar is 127. That can be easily
- modified by creating a larger buffer and setting BufPtr and BufSize
- in InitTFDD().
- }
-
- {-------------------------------}
- Interface
- {-------------------------------}
- uses windos;
-
- var
- ZOut : text; { text file to Write() to }
-
- function GetZ : PChar;
- { returns PChar() result from previous Write(Zout,,)}
-
- {-------------------------------}
- Implementation
- {-------------------------------}
-
- function GetZ : PChar;
- begin
- getz := PChar(ttextrec(ZOut).BufPtr);
- end;
-
- Function OpenProc(VAR F : TTextRec) : Integer; far;
- { initialize Zout for output }
- BEGIN
- OpenProc := 0;
- F.mode := fmOutput;
- F.BufPos := 0;
- END;
-
- { TFDD InOut function }
- Function ZTFDDout(VAR F : TTextRec) : Integer; far;
- BEGIN
- { make bufptr^ an asciiz }
- if (f.bufpos = f.bufsize) then dec(f.bufpos);
- f.bufptr^[f.bufpos] := #0;
- f.BufPos := 0; { reset bufpos for next Write() }
- ZTFDDout := 0; { Set IoResult code }
- END;
-
- Procedure InitTFDD(VAR F : Text);
- { Initialize TFDD TTextRec, and open it for output }
- BEGIN
- With TTextRec(F) Do BEGIN
- Handle := 0;
- mode := fmClosed;
- BufSize := sizeof(ttextbuf);
- BufPtr := @Buffer;
- BufPtr^[0] := #0;
- OpenFunc := @OpenProc;
- InOutFunc := @ZTFDDout;
- FlushFunc := @ZTFDDout;
- END;
- ReWrite(F);
- END;
-
- BEGIN
- InitTFDD(Zout); { Open Zout TFDD }
- END.
-